import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button } from 'antd';
import { WeaRichText,WeaNewScroll, WeaPopoverHrm, WeaLocaleProvider } from 'ecCom';
import FeedBack from '../../../public/feedback/FeedBack';
import { getParams, getCurrentHeight, setWindowKeys } from '../../../util/Util';
const toJS = mobx.toJS;
const getLabel = WeaLocaleProvider.getLabel;
@inject('planViewStore')
@observer
export default class Feedback extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            _height:getCurrentHeight()
        };
        this.store = this.props.planViewStore;
    }


    saveFeedback = () => {
        this.store.addPlanExchange();
        this.store.setValue('feedback', '');
    };

    getNameALink = (resourceid, resourcename) => {
        let href = 'javaScript:openhrm(' + resourceid + ');';
        return (
            <a href={href} onClick={e => window.pointerXY(e)} class="autoWrap">
                {resourcename}
            </a>
        );
    };
    formatFblist = list => {
        let result = [];
        list.map(v => {
            result.push({
                operatedate: v.datetime,
                hrmid: v.hrmid,
                hrmname: v.hrmname,
                content: v.content,
            });
        });
        return result;
    };

    richTextChange = v => {
        this.store.setValue('feedback', v);
    };

    render() {
        let {_height} = this.state
        let { fblist } = this.store;
        fblist = fblist ? toJS(fblist) : [];
        fblist = this.formatFblist(fblist);
        return (
            <div className="plan-feedback">
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@cls1h5`} height={_height - 180}>
                    <WeaRichText ecId={`${this && this.props && this.props.ecId || ''}_WeaRichText@ojw3g8`}
                        ckConfig={{
                            startupFocus: false,
                            toolbar: [
                                { name: 'document', items: ['Source'] },
                                { name: 'styles', items: ['Format', 'Font', 'FontSize'] },
                                { name: 'insert', items: ['Table', 'Smiley'] },

                                {
                                    name: 'paragraph',
                                    items: [
                                        'JustifyLeft',
                                        'JustifyCenter',
                                        'JustifyRight',
                                        '-',
                                        'NumberedList',
                                        'BulletedList',
                                    ],
                                },

                                { name: 'colors', items: ['TextColor'] },
                                {
                                    name: 'basicstyles',
                                    items: ['Bold', 'Italic', 'Underline', 'Strike'],
                                },
                            ],
                            height: 100,
                            autoGrow_minHeight: 100,
                            autoGrow_maxHeight: 200,
                            resize_enabled: false,
                        }}
                        value={this.store.feedback}
                        onChange={v => this.richTextChange(v)}
                        bottomBarRight={{
                            width: 100,
                            Component: [
                                <span
                                    className="wea-rich-text-toolbar-bottom-item"
                                    style={{ position: 'relative' }}
                                >
                                    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@3yebab@submit`}
                                        className="wea-button-release"
                                        onClick={this.saveFeedback}
                                    >
                                        <span>
                                            <span className="icon-coms-Release" />
                                            <span style={{ marginLeft: '2px' }}>{getLabel('615', '提交')}</span>
                                        </span>
                                    </Button>
                                </span>,
                            ],
                        }}
                    />

                    <FeedBack ecId={`${this && this.props && this.props.ecId || ''}_FeedBack@kxqqkx`} dataSource={fblist} style={{ marginTop: "10px" }} />
                </WeaNewScroll>
            </div>
        );
    }
}
